www.gusucode.com > VC++ 酒店管理系统-源码程序 > VC++ 酒店管理系统-源码程序/code/hotel2003/ChooseRoom.cpp
// ChooseRoom.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "qq.h" #include "ChooseRoom.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CChooseRoom dialog CChooseRoom::CChooseRoom(CWnd* pParent /*=NULL*/) : CDialog(CChooseRoom::IDD, pParent) { //{{AFX_DATA_INIT(CChooseRoom) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CChooseRoom::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CChooseRoom) DDX_Control(pDX, IDC_HANDCODE, HandCode); DDX_Control(pDX, IDC_BILLCODE, BillCode); DDX_Control(pDX, IDC_ROOMSELNUM, RoomSelNum); DDX_Control(pDX, IDC_ROOMSUM, RoomSum); DDX_Control(pDX, IDC_ROOMBILLLIST, RoomBillList); DDX_Control(pDX, IDC_ROOMCODELIST, RoomCodeList); DDX_Control(pDX, IDC_ROOMPRICE, RoomPrice); DDX_Control(pDX, IDC_ROOMTYPE, RoomType); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CChooseRoom, CDialog) //{{AFX_MSG_MAP(CChooseRoom) ON_CBN_SELCHANGE(IDC_ROOMTYPE, OnSelchangeRoomtype) ON_BN_CLICKED(IDC_ADD, OnAdd) ON_BN_CLICKED(IDC_DELETE, OnDelete) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CChooseRoom message handlers BOOL CChooseRoom::OnInitDialog() { CDialog::OnInitDialog(); HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2); this->SetIcon(m_hIcon,true);//设置对话框图标 // TODO: Add extra initialization here ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// RoomType.SetWindowText("标准单人房"); RoomType.AddString("标准单人房");//index==0 RoomType.AddString("标准双人房"); RoomType.AddString("贵族单人房"); RoomType.AddString("贵族双人房");//index==3 ////////////////////////////////// //产生帐单号码 CCreateBillCode billcode; BillCode.SetWindowText(billcode.GenereBillCodeForCheckOut()); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CChooseRoom::OnSelchangeRoomtype() { // TODO: Add your control notification handler code here ///删除以前的记录 this is a bug!!!! RoomCodeList.ResetContent();//清除所有的项目 CString strComboText;//combobox中的文本 RoomType.GetLBText(RoomType.GetCurSel(),strComboText);//获得选择的文本 ///////////////////////////////////////////////////////////////// // 进行数据库的查询 //roomprice fill CString SQLstr; SQLstr="SELECT * FROM RoomInfo where RoomType='" ; SQLstr=SQLstr+strComboText; SQLstr=SQLstr+"'"; if(!m_RoomInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr)) {//查询数据库得到数据集合 AfxMessageBox("打开数据库失败!"); return ; } CString str; str.Format("%5.00f",m_RoomInfoSet.m_Price); RoomPrice.SetWindowText(str); m_RoomInfoSet.Close(); //关闭数据库 ///////////////////////////////////////////////////////////// if(!m_RoomInfoSet.Open()) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } m_RoomInfoSet.MoveFirst(); while(!m_RoomInfoSet.IsEOF()) { if(m_RoomInfoSet.m_RoomType==strComboText) { if(m_RoomInfoSet.m_RoomStatus=="空") { RoomCodeList.AddString(m_RoomInfoSet.m_RoomCode); } } m_RoomInfoSet.MoveNext(); } m_RoomInfoSet.Close(); //////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// int n=RoomCodeList.GetCount(); CString strRoomNum; strRoomNum.Format("%d",n); RoomSum.SetWindowText(strRoomNum);//设置总数窗口文本 } void CChooseRoom::OnAdd() { // TODO: Add your control notification handler code here //将roomcode info add to billinfolist CString strRoomCode; if(RoomCodeList.GetCount()==0) { return; } else { if(RoomCodeList.GetCurSel()!=-1) { RoomCodeList.GetText(RoomCodeList.GetCurSel(),strRoomCode); } } if(RoomCodeList.GetCurSel()==-1) { MessageBox("请选择一个房间","数据为空错误",MB_OK); return ; } CString BillinfoText=strRoomCode; int n=RoomBillList.GetCount(); CString strTemp=""; bool bSame=false; for(int i=0;i<n;i++) { RoomBillList.GetText(i,strTemp); if(strTemp==strRoomCode) { MessageBox("你已经选择了这个房间!","选择错误",MB_OK); bSame=true; return; } } if(!bSame) { RoomBillList.AddString(BillinfoText); } //////////////////////////////////////////////////////////////////// //统计当前的帐单数目 int m=RoomBillList.GetCount(); CString strSelNum; strSelNum.Format("%d",m);//必须再调用一次getcount()函数 RoomSelNum.SetWindowText(strSelNum); } void CChooseRoom::OnOK() {//保存数据 // TODO: Add extra validation here CString strHandCode; HandCode.GetWindowText(strHandCode); if(strHandCode=="") { MessageBox("请输入手牌号!","数据为空错误",MB_OK); return; } CString strSelNum; RoomSelNum.GetWindowText(strSelNum); if(strSelNum=="") { MessageBox("你至少要选择一个房间!","选择错误",MB_OK); return; } if(!m_GuestInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE)) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } m_GuestInfoSet.MoveFirst(); bool bhas=false; while(!m_GuestInfoSet.IsEOF()) { if(m_GuestInfoSet.m_HandCode==strHandCode) { ////////////////////////////////////////////////////////////////////////// /// 数据填充 m_GuestInfoSet.Edit();//进行编辑,写入到缓冲区中 m_GuestInfoSet.m_RoomNum=strSelNum;//将当前选择的房间数目保存到数据库中 CString strShowText="",strtemp=""; int num=RoomBillList.GetCount(); for(int i=0;i<num;i++) {//调用RoomBillList.GetDlgITemText(i,strtemp)会失败 RoomBillList.GetText(i,strtemp); strShowText=strShowText+strtemp+","; } m_GuestInfoSet.m_RoomCode=strShowText; m_GuestInfoSet.Update();//更新数据 bhas=true;//存在这条记录 break; } m_GuestInfoSet.MoveNext();//移动到下一条记录 } if(!bhas) { MessageBox("你输入的手牌号不正确!","输入信息错误",MB_OK); m_GuestInfoSet.Close();//关闭数据库 return; } m_GuestInfoSet.Close();//关闭数据库 ////写客房信息数据库表 if(!m_RoomInfoSet.Open()) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } CString strRoomRestor=""; for(int i=0;i<RoomBillList.GetCount();i++) { RoomBillList.GetText(i,strRoomRestor); m_RoomInfoSet.MoveFirst(); while(!m_RoomInfoSet.IsEOF()) { if(strRoomRestor==m_RoomInfoSet.m_RoomCode) { m_RoomInfoSet.Edit();//edit the DB m_RoomInfoSet.m_RoomStatus="住人";//改变roominfoset的roomstatus CString SQLStr,strHandCode; HandCode.GetWindowText(strHandCode); SQLStr="select * from GuestInfo where HandCode='"; SQLStr=SQLStr+strHandCode; SQLStr=SQLStr+"'"; if(!m_GuestInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLStr)) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } m_RoomInfoSet.m_PriceType=m_GuestInfoSet.m_IsMember; m_GuestInfoSet.Close();//关闭客人信息数据库 m_RoomInfoSet.Update(); } m_RoomInfoSet.MoveNext(); } } m_RoomInfoSet.Close();//关闭数据库 ///将帐单号码写入BillCheckoutInfo表中 if(!m_BillCheckoutInfoSet.Open()) { MessageBox("打开数据库失败!","数据库错误",MB_OK); return; } m_BillCheckoutInfoSet.MoveFirst();//first while (!m_BillCheckoutInfoSet.IsEOF()) { if(strHandCode==m_BillCheckoutInfoSet.m_HandCode) { m_BillCheckoutInfoSet.Edit();//编辑数据库 CString strBillCode; BillCode.GetWindowText(strBillCode);//得到账单号码 m_BillCheckoutInfoSet.m_BillCode=strBillCode; m_BillCheckoutInfoSet.Update(); } m_BillCheckoutInfoSet.MoveNext(); } m_BillCheckoutInfoSet.Close();//关闭数据库 CDialog::OnOK(); } void CChooseRoom::OnDelete() { // TODO: Add your control notification handler code here int nCurSel=RoomBillList.GetCurSel(); if(nCurSel==-1) { MessageBox("请选择一个要删除的房间号","数据为空错误",MB_OK); return; } RoomBillList.DeleteString(nCurSel); /////////更新显示 int m=RoomBillList.GetCount(); CString strSelNum; strSelNum.Format("%d",m); RoomSelNum.SetWindowText(strSelNum); } void CChooseRoom::OnCancel() { // TODO: Add extra cleanup here CDialog::OnCancel(); }